<?php
namespace api\know\controller;

use api\wxapp\controller\PublicController;
use api\know\model\MaterialModel;
use api\know\model\TeachingMaterialContentModel;
use api\know\model\ResourceModel;
use api\know\model\TeachingMaterialKnowledgePointModel;
use api\know\model\TeachingMaterialNewWordModel;
use api\know\model\GrammarModel;
use api\know\model\GrammarQuestionModel;
use api\know\model\GrammarExampleModel;
use api\know\model\QuestionModel;
use think\facade\Log;

class GrammarController extends PublicController
{
    public function detail()
    {
        $uuid = $this->request->param('uuid', '');
		if (empty($uuid))
        {
            $this->error('语法不能为空!');
        }

        $g_wh[] = ['is_delete', '=', 0];
        $g_wh[] = ['is_enable', '=', 1];
        $g_wh[] = ['uuid', '=', $uuid];

        $g = GrammarModel::where($g_wh)->field(GrammarModel::$QueryField)->find();
		if (empty($g)) 
		{
			$this->error('语法不存在!');
		}
        $g['analysis'] = htmlspecialchars_decode(htmlspecialchars_decode($g['analysis']));
        $lst = GrammarQuestionModel::where('grammar_uuid', '=', $uuid)->field(GrammarQuestionModel::$QueryField)->select()->toArray();

        $questions = [];
        foreach($lst as $v)
        {
            $item = QuestionModel::getQuestion($v['question_uuid']);
            array_push($questions, $item);
        }

        $examples = GrammarExampleModel::where('grammar_uuid', '=', $uuid)->field(GrammarExampleModel::$QueryField)->select();
		
        $this->success('请求成功!', [
            'content' => $g,
            'question' => $questions,
			'example' => $examples,
        ]);
    }

}
